import { apiPost, apiGet } from './client';

// AI interface type definitions
export interface AIMessage {
  role: 'system' | 'user' | 'assistant';
  content: string;
}

export interface GenerateResponseRequest {
  messages: AIMessage[];
  personaPrompt: string;
  model?: string;
}

export interface GenerateResponseResponse {
  content: string;
  usage?: {
    promptTokens: number;
    completionTokens: number;
    totalTokens: number;
  };
  model: string;
  provider: 'qwen';
}

export interface TTSRequest {
  text: string;
  voice?: string;
  format?: string;
  language?: string;
}

export interface TTSResponse {
  audioUrl: string;
  duration: number;
  format: string;
}

export interface ASRRequest {
  audioData: string; // base64
  language?: string;
  mimeType?: string;
}

export interface ASRResponse {
  text: string;
  confidence: number;
  duration: number;
  language: string;
}

export interface HealthCheckResponse {
  qwen: boolean;
  elevenlabs: boolean;
  deepgram: boolean;
}

export const aiApi = {
  // Generate AI response
  async generateResponse(data: GenerateResponseRequest): Promise<GenerateResponseResponse> {
    return await apiPost('/ai/generate', data);
  },

  // Text to speech
  async textToSpeech(data: TTSRequest): Promise<TTSResponse> {
    return await apiPost('/ai/tts', data);
  },

  // Speech to text
  async speechToText(data: ASRRequest): Promise<ASRResponse> {
    return await apiPost('/ai/asr', data);
  },

  // Health check
  async checkHealth(): Promise<HealthCheckResponse> {
    return await apiPost('/ai/health', {});
  },
};
